﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using FineUI;
using SDLITS.Model;
using SDLITS.Common;
using MySoft.Data;
using System.Data;
using System.Data.SqlClient;

namespace SDLITS.Web.Driver
{
    public partial class DealCardManage : CommonBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                
            }
        }
        private void BindGrid()
        {
            SqlParameter[] sp = new SqlParameter[]{
                    new SqlParameter("@MemCardNo",txt_no.Text.Trim()),
                    new SqlParameter("@SPAction","SelectByMCNO")
                };
            DataSet ds = SDDbSession.Default.FromProc("TableLEDMessage").AddParameter(sp).ToDataSet();
            if (ds != null && ds.Tables.Count > 0)
            {
                Grid1.Hidden = false;
                Grid1.DataSource = ds.Tables[0];
                Grid1.DataBind();
                if (ds.Tables[0].Rows.Count>0)
                {
                    DataRow dr = ds.Tables[0].Rows[0];
                    var mp = new ModelPrint
                    {
                        CompanyIDNumber = dr["IDNumber"] is DBNull ? "" : dr["IDNumber"].ToString()
                    };
                    Session["ModelPrint"] = mp;
                }
            }
        }
        private bool IsCompanyCard()
        {
            int s=SDDbSession.Default.From<MemCard>().Where(MemCard._.StatusID == 1 && MemCard._.MemTypeID == 3 && MemCard._.MemCardNo == txt_no.Text.Trim()).Count();
            return s>0;
        }
        protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
        {
            Grid1.PageIndex = e.NewPageIndex;
            BindGrid();
        }

        protected void txt_no_TextChanged(object sender, EventArgs e)
        {
            if (IsCompanyCard())
            {
                BindGrid();
            }
            else
            {
                Alert.Show("没有对应的企业卡，请检查后重新输入！");
            }
        }
    }
}
